package br.biofoco.p2p.dht;

import java.io.IOException;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;

import br.biofoco.p2p.peer.IDFactory;
import br.biofoco.p2p.peer.PeerConfig;
import br.biofoco.p2p.peer.PeerNode;
import br.biofoco.p2p.peer.JsonPeerSerializer;
import br.biofoco.p2p.peer.ProxyPeer;
import br.biofoco.p2p.rpc.EndPoint;
import br.biofoco.p2p.rpc.tcp.TcpEndPoint;

public class PeerSerializerTest {
	
	public static void main(String[] args) throws JsonGenerationException, JsonMappingException, IOException {
		
		PeerConfig config = new PeerConfig();
		config.setPeerID(IDFactory.newRandomID());
//		config.setPeerName("teste1");
		String address = InetAddress.getLocalHost().getHostAddress();
		List<EndPoint> list = new ArrayList<EndPoint>(Arrays.asList(new TcpEndPoint(address, 7373)));
		config.addEndPoints(list);
					
		PeerNode p = new ProxyPeer(config);		
		String lista = new JsonPeerSerializer().serialize(Arrays.asList(p,p));		
		System.out.println(lista);		
		
		new JsonPeerSerializer().unserializeCollection(lista);
		
//		ObjectMapper m = new ObjectMapper();
//		ByteArrayOutputStream baos = new ByteArrayOutputStream();
//		m.writeValue(baos, config);
//		
//		System.out.println(baos.toString("UTF-8"));
	}

}
